package com.block.api.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.block.account.service.IAccountApplyRecordService;
import com.block.common.bean.CommonParam;
import com.block.common.exception.ApiException;
import com.block.common.security.util.ApiUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/admin/account")
@Validated
public class AccountController {

    @Autowired
    IAccountApplyRecordService accountApplyRecordService;

    /**
     * 入账申请  进行 入账操作
     */
    @RequestMapping(value = "/entryAccount", method = {RequestMethod.POST, RequestMethod.GET})
    public String entryAccount(@RequestAttribute(value = "tranData") JSONObject tranData,
                              @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                              @RequestAttribute(value = "uri") String uri,
                              @RequestAttribute(value = "commonParam") CommonParam commonParam,
                              @RequestAttribute(value = "startDate") Date startdate,
                              @RequestAttribute(value = "ip") String ip) throws ApiException {

        String recordId = tranData.getString("recordId");// 生成的账单日期
        String operatorId = tranData.getString("operatorId");// 数据ID
        String operatorName = tranData.getString("operatorName");// 数据类型

        ResponseVo responseVo = accountApplyRecordService.entryAccount(recordId, operatorId, operatorName);

        return ApiUtil.dealReturnJson(responseVo, appEncrypt, "1.0", startdate, uri);
    }


}
